<?php
/*
+--------------------------------------------------------------------------
|   phpBIZ v3.0  full version
|   ========================================
|   by taft@wjl.cn yejun@wjl.cn
|   http://www.phpbiz.cn http://www.wjl.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 最后修改日期：2005-4-30 2006-2-8
|
+--------------------------------------------------------------------------
*/
!class_exists('Debug') && exit('Forbidden');
$idx = new Main;

class Main
{
	var $base_url;

	function Main()
	{
		global $BIZ,$DB,$CONF,$ID,$cache;

		if($BIZ->is_cached("Main.tpl",$BIZ->seller['seller_id'],$BIZ->cache_id))
		{
			$BIZ -> output('Main.tpl',true,$BIZ->seller['seller_id']);   //caching his own main page
		}
        
		define("BOTTON_LIST",8);
		
		//------------------------------------

		//-----------------------------------
		//read cat info
		//----------------------------------
				
		$minutes = 24*60;
        $cache_file='cache/cat_cache.php';
		if(time()-@filemtime($cache_file) > $minutes*60)
		{
		$DB -> db_query( " SELECT a.goods_cat_name as aname,a.goods_cat_id as aid,b.goods_cat_name as bname,b.goods_cat_id as bid FROM biz_goods_cat a LEFT JOIN biz_goods_cat b ON b.goods_cat_parent_id =a.goods_cat_id WHERE a.goods_cat_parent_id = 0 ORDER BY a.goods_cat_id ASC");
		
		$ca = array();
		$bm5a= array();

		$r = $DB -> db_fetch_row();
		$pre_id = $r['aid'];
		$ca[] = array($r['aname'],$r['aid'],"","");
		$ca[] = array("","",$r['bname'],$r['bid']);
		while( $r = $DB -> db_fetch_row() )
		{
			if( $pre_id != $r['aid'] ) 
			{
				$ca[] = array($r['aname'],$r['aid'],"","");
				$pre_id = $r['aid'];
			}
			if($r['bid']) $ca[] = array("","",$r['bname'],$r['bid']);
		}
		$catcache="\$_CAT=array(\r\n";
		$catcache.=$cache -> array_export($ca);
		$catcache.=");\r\n";
		$cache->write_cache($cache_file,"<?php\r\n$catcache?>");
		}
		include $cache_file;
	
		$BIZ -> assign("ca",$_CAT[0]);
		$BIZ -> fetch("cat_cache.tpl");
		
		//------------------------------------

		//------------------------------------
		//best goods / newest goods
		//------------------------------------
		$a = array();
		$c = array();
		$d = array();
        $DB -> db_query( "SELECT goods_id,goods_name,goods_price,p.pic_name FROM biz_goods g LEFT JOIN biz_pic p ON p.pic_id = g.goods_prime_picture_id WHERE p.pic_id > 1 AND g.goods_mark_sell='0' AND goods_end_active_time >".time()." ORDER BY goods_visit_count DESC LIMIT 0,".BOTTON_LIST);
		while( $r = $DB -> db_fetch_row() )
		        $a[] = array( $r['goods_id'],$r['goods_name'],$r['goods_price'],$BIZ->get_thumb($r['pic_name']) );
		
		/*with pic*/
		$DB -> db_query("SELECT g.*, p.pic_name FROM biz_goods g LEFT JOIN biz_pic p ON p.pic_id = g.goods_prime_picture_id WHERE p.pic_id > 1 AND g.goods_mark_sell='0' ORDER BY goods_store_date DESC LIMIT 0,6"  );
		
		$newest6a = array();  
		while( $newest6 = $DB -> db_fetch_row() )
		{
			$newest6a[] = array( $newest6['goods_id'],substrs($newest6['goods_name'],10),$BIZ->get_thumb($newest6['pic_name']),$newest6['goods_price']);
		}

		/*without pic*/
		$DB -> db_query("SELECT goods_id,goods_name,goods_price FROM biz_goods WHERE  goods_mark_sell='0'   AND goods_prime_picture_id = 1 ORDER BY goods_store_date DESC LIMIT 8");
		while($r=$DB -> db_fetch_row())
		{
			$d[] = array( $r['goods_id'],$r['goods_name'],$r['goods_price'] );
		}
		
		$BIZ -> assign("a",$a);  //best renqi
		$BIZ -> assign("c",$newest6a); //newest with pics
		$BIZ -> assign("d",$d);
	 
	    //------------------------------------

		//------------------------
		//read new shop  marquee
		//------------------------
		$DB -> db_query( "SELECT s.*, p.pic_name FROM biz_shop s, biz_pic p WHERE p.pic_id = s.shop_prime_picture_id   AND p.pic_id <> 1 AND s.shop_check_status ='checked' AND s.shop_ban_status ='off' ORDER BY s.shop_create_time DESC LIMIT 0,6" );

		$newa = array();
		
		while( $new = $DB -> db_fetch_row() )
		{
 			$new['shop_name'] = substrs($new['shop_name'],25);
			$newa[] = array( $new['shop_id'],$new['shop_name'],$BIZ->get_thumb($new['pic_name']));
		}
		$BIZ -> assign("new",$newa);

		//read trust shop by yejun

		$DB -> db_query( "SELECT s.shop_id,s.shop_name FROM biz_shop s WHERE s.shop_check_status ='checked' AND s.shop_ban_status ='off' AND s.shop_set_top = ".TRUST_SHOP." ORDER BY s.shop_global_recommend DESC LIMIT 0,5" );

		$aTrust = array();
		
		while( $Trust = $DB -> db_fetch_row() )
		{
 			$Trust['shop_name'] = substrs($Trust['shop_name'],25);
			$aTrust[] = array( $Trust['shop_id'],$Trust['shop_name']);
		}
		$BIZ -> assign("aTrust",$aTrust);
		$BIZ -> output('Main.tpl',true,$BIZ->seller['seller_id']);
	}
}
